package com.system.jfm.Components;
import com.system.jfm.Components.PlaceHolder;

import javax.swing.*;

public class LabelTextField extends JPanel {
    public JLabel label;
    JTextField txt_box;

    String hint_txt = "";
    public LabelTextField(String label_txt, int width, int height, double per){
        label = new JLabel(label_txt);
        txt_box = new JTextField();
        this.setSize(width,height);

        label.setBounds(0,0,(int) (width*per),height);
        txt_box.setBounds(label.getWidth(),0,this.getWidth()-label.getWidth(),height);


        this.setSize(width,height);
        this.setLayout(null);

        this.add(label);
        this.add(txt_box);
    }

    LabelTextField(String label_txt,int label_width,int label_height,int txt_width,int txt_height){
        label = new JLabel(label_txt);
        txt_box = new JTextField();

        this.setSize(label_width+txt_width,label_height+txt_height);

        label.setBounds(0,0,label_width,label_height);
        txt_box.setBounds(label_width,0,txt_width,txt_height);

        this.setLayout(null);

        this.add(label);
        this.add(txt_box);
    }

    public String getText(){
        return txt_box.getText();
    }

    public void setPlaceHolder(String hitTxt) {
        this.hint_txt = hitTxt;
        txt_box.addFocusListener(new PlaceHolder(txt_box,hitTxt));
    }

    public void setLabelHorizontalAlignment(int arg){
        label.setHorizontalAlignment(arg);
    }

    public boolean isEmpty(){
        return this.hint_txt.equals(this.getText());
    }

}
